package com.vinjogames.som.entities;

import android.graphics.PointF;

public class LineSegment {
	public PointF start, end;
	public boolean horizontal;
	
	public LineSegment(PointF st, PointF en) {
		start = st; end = en;
		horizontal = (st.y == en.y);
	}
	
	public boolean intersects(LineSegment other) {
		if(horizontal == other.horizontal) {
			return (start.y == other.start.y) && horizontal
				|| (start.x == other.start.x); 
		}
		else if(horizontal) {
			if(start.y >= other.start.y && start.y <= other.end.y
			|| start.y >= other.end.y && start.y <= other.start.y)
				return true;
		}
		else {
			if(start.x >= other.start.x && start.x <= other.end.x
			|| start.x >= other.end.x && start.x <= other.end.x)
				return true;
		}
		return false;
	}
}
